<template>
    <div>
        <!-- ticketManage -->
        <el-row>
            <el-col :span="24">
                <div class="container">
                    <el-row>
                        <el-col :span="24" class="table-fun">
                            <img src="../../assets/imgs/operation_icon_shuaxin_default.png" alt="" class="lf"><div class="lf choose-title2 fun-text" @click="refresh">刷新</div>
                            <img src="../../assets/imgs/operation_icon_tianjia_default.png" alt="" class="lf"><div class="lf choose-title2 fun-text" @click="amWin=true;winTitle='添加'">添加</div>
                            <img src="../../assets/imgs/operation_icon_xiugai_default.png" alt="" class="lf"><div class="lf choose-title2 fun-text" @click="amWin=true;winTitle='修改'">修改</div>
                            <img src="../../assets/imgs/operation_icon_zuofei_default.png" alt="" class="lf"><div class="lf choose-title2 fun-text" @click="abandon">作废</div>
                            <img src="../../assets/imgs/operation_icon_huifu_default.png" alt="" class="lf"><div class="lf choose-title2 fun-text" @click="recover">恢复</div>
                        </el-col>
                    </el-row>
                    <el-row>
                      <el-col :span="24">
                          <!-- 表格内容 -->
                          <avue-crud :data="ticketList[0].data" :option="ticketList[0].option" @current-row-change="rowChange" :page="ticketList[0].page" @current-change="ticketPage"></avue-crud>
                      </el-col>
                  </el-row>
                  <!-- 弹窗 -->
                  <div class="modal-win" v-show="amWin">
                    <!-- 标题栏 -->
                    <el-row class="add-title">
                        <div class="closeWin" @click="amWin=false">X</div>
                        <el-col :span="24">
                            <img src="../../assets/imgs/operation_bg_biaoti_default.png" alt=""><span class="add-text">{{winTitle}}</span>
                        </el-col>
                    </el-row>
                    <!-- 表单栏 -->
                    <avue-form ref="form" v-model="ticketForm.data" :option="ticketForm.option" class="yz-form"></avue-form>
                    <button class="check-btn rf" @click="amWin=false"><img src="../../assets/imgs/operation_btn_icon_quxiao_default.png" alt="" class="btn-img">取消</button>
                    <button class="check-btn rf" @click="winTitle=='添加'?add(ticketForm.data):mod()"><img src="../../assets/imgs/operation_btn_icon_tijiao_default.png" alt="" class="btn-img">确认</button>
                  </div>
                </div>
            </el-col>
        </el-row>
        
        
    </div>
</template>

<script>
import qs from "qs";
import TableData from "../../components/common/tableData"
const DIC={
  shiM:[
    {
      label:"是",
      value:1
    },
    {
      label:"否",
      value:0
    },
  ],
  zeroSell:[
    {
      label:"是",
      value:1
    },
    {
      label:"否",
      value:0
    },
  ],
  fuJia:[
     {
      label:"是",
      value:1
    },
    {
      label:"否",
      value:0
    },
  ]
}
export default {
  data: function() {
    return {
      activeTag:"5-6",
      ticketList: [
        {
           page: {
            pageSizes: [10],
            total: 2,
            currentPage: 1,
            pageSize: 10
          },
          data: [],
          option: {
            page: true,
            stripe: true,
            menu: false,
            highlightCurrentRow:true,
            align: "center",
            menuAlign: "center",
            column: []
          }
        }
      ],
      currentRow:"",
      amWin:false,
      winTitle:"test",
      ticketForm:{
        data:{},
        option:{
          dicData:DIC,
          column:[
            {
              label:"车票名称",
              prop:"ticName",
              span:17
            },
            {
              label:"实名登记",
              prop:"trueName",
              type:"select",
              dicData:"shiM",
              span:8
            },
            {
              label:"零元出售",
              prop:"zeroSell",
              type:"select",
              dicData:"zeroSell",
              span:8
            },
            {
              label:"附加费",
              prop:"fuJiaPrice",
              type:"select",
              dicData:"fuJia",
              span:8
            },
            {
              label:"消耗票数",
              prop:"costCount",
              span:12
            },
            {
              label:"票价%",
              prop:"pricePercent",
              span:12
            },
          ]
        }
      }
    };
  },
  methods: {
    ticketPage(val){
      this.ticketList[0].page.currentPage=val;
      this.getTicketList();
    },
    getTicketList() {
      this.postRequest("/tks/type/list",{
        rows:10,
        page:this.ticketList[0].page.currentPage
      }).then(data => {
        this.ticketList[0].page.total=data.data.totalRow;
        this.ticketList[0].data=data.data.list;
      });
    },
    refresh() {
      this.getTicketList();
    },
    add(item) {
      this
        .getRequest(
          "/tks/type/add?tksType.id=&tksType.name="+item.ticName+"&tksType.needs_id_reg="+item.trueName+"&tksType.is_enable_zero_price="+item.zeroSell+"&tksType.is_enable_surcharge="+item.fuJiaPrice+"&tksType.bill_cost="+item.costCount+"&tksType.percent="+item.pricePercent
        )
        .then(data => {
          if (data.data[0] == 0) {
            this.$message({
              message: data.data[1],
              type: "success"
            });
            this.getTicketList();
            this.amWin=false;
          } else {
            this.$message.error(data.data[1]);
          }
        });
    },
    mod() {
      this
        .getRequest(
          "/tks/type/update?tksType.id=&tksType.name="+item.ticName+"&tksType.needs_id_reg="+item.trueName+"&tksType.is_enable_zero_price="+item.zeroSell+"&tksType.is_enable_surcharge="+item.fuJiaPrice+"&tksType.bill_cost="+item.costCount+"&tksType.percent="+item.pricePercent
        )
        .then(data => {
          if (data.data[0] == 0) {
            this.$message({
              message: data.data[1],
              type: "success"
            });
            this.getTicketList();
          } else {
            this.$message.error(data.data[1]);
          }
        });
    },
    abandon() {
      this
        .postRequest(
          "/tks/type/del",{
            id:this.currentRow.id
          }
        )
        .then(data => {
          if (data.data[0] == 0) {
            this.$message({
              message: data.data[1],
              type: "success"
            });
            this.getTicketList();
          } else {
            this.$message.error(data.data[1]);
          }
        });
    },
    recover() {
      this
        .postRequest("/tks/type/Back?",{
          id:this.currentRow.id
        })
        .then(data => {
          if (data.data[0] == 0) {
            this.$message({
              message: data.data[1],
              type: "success"
            });
            this.getTicketList();
          } else {
            this.$message.error(data.data[1]);
          }
        });
    },
    tableCreate() {
      this.ticketList[0].option.column.push(
        {
          label: "票务名称",
          prop: "name"
        },
        {
          label: "%",
          prop: "percent"
        },
        {
          label: "实名",
          prop: "needs_id_reg",
           formatter:function(row, value , label, column){
            return row.needs_id_reg?"是":"否"
          }
        },
        {
          label: "允许零元出售",
          prop: "is_enable_zero_price",
          formatter:function(row, value , label, column){
            return row.is_enable_zero_price?"是":"不允许"
          }
        },
        {
          label: "收取附加费",
          prop: "is_enable_surcharge",
          formatter:function(row, value , label, column){
            return row.is_enable_surcharge?"是":"否"
          }
        },
        {
          label: "消耗票数",
          prop: "bill_cost"
        },
        {
          label: "创建者",
          prop: "create_user_name"
        },
        {
          label: "创建时间",
          prop: "create_time"
        },
        {
          label: "更新者",
          prop: "update_user"
        },
        {
          label: "更新时间",
          prop: "update_time"
        },
        {
          label:"",
          prop:"del_flag",
          formatter:function(row, value , label, column){
            return row.del_flag?"已报废":""
          }
        },
      );
    },
    rowChange(val){
      this.currentRow=val;
      console.log(val);
      if(this.winTitle=="修改"){
        this.ticketForm.data.ticName=this.currentRow.name;
        this.ticketForm.data.trueName=this.currentRow.needs_id_reg?"是":"否";
        this.ticketForm.data.zeroSell=this.currentRow.is_enable_zero_price?"是":"否";
        this.ticketForm.data.fuJiaPrice=this.currentRow.is_enable_surcharge?"是":"否";
        this.ticketForm.data.costCount=this.currentRow.bill_cost;
        this.ticketForm.data.pricePercent=this.currentRow.percent;
      }
    }
  },
  computed: {},
  components:{TableData},
  watch: {
    winTitle(){
      if(this.winTitle=="添加"){
        this.ticketForm.data.ticName="";
        this.ticketForm.data.trueName="";
        this.ticketForm.data.zeroSell="";
        this.ticketForm.data.fuJiaPrice="";
        this.ticketForm.data.costCount="";
        this.ticketForm.data.pricePercent="";
      }else{
        this.ticketForm.data.ticName=this.currentRow.name;
        this.ticketForm.data.trueName=this.currentRow.needs_id_reg;
        this.ticketForm.data.zeroSell=this.currentRow.is_enable_zero_price;
        this.ticketForm.data.fuJiaPrice=this.currentRow.is_enable_surcharge;
        this.ticketForm.data.costCount=this.currentRow.bill_cost;
        this.ticketForm.data.pricePercent=this.currentRow.percent;
      }
    }
  },
  mounted() {
    console.log("ticketManage");
    this.$emit("sendActive",this.activeTag);
    this.tableCreate();
    this.getTicketList();
  }
};
</script>
<style scoped src="../../assets/css/service/ticketManage.css">

</style>